/**
 *
 * 2007-11-1 下午08:08:27
 * @author xuhuan
 */

package edu.ccut.saturn.studio.logic.model.saturn;

import java.util.ArrayList;
import java.util.List;

public class SaturnParameter implements Comparable<SaturnParameter> {

	public boolean equals(SaturnParameter parameter) {
		if(!(parameter instanceof SaturnParameter)){
			return false;
		}
		if (this.name.equals(((SaturnParameter)parameter).getName())
				&& this.classType.equals(((SaturnParameter)parameter).getClassType())
				&& this.passingType.equals(((SaturnParameter)parameter).getPassingType())
				&& this.valueKey.equals(((SaturnParameter)parameter).getValueKey())
				&& this.description.equals(((SaturnParameter)parameter).getDescription())
				&& this.scope.equals(((SaturnParameter)parameter).getScope())
				&& this.isValidate.equals(((SaturnParameter)parameter).getIsValidate())
				&& isModifyValidata(((SaturnParameter)parameter))) {
			
			return true;
		}
		return false;
	}

//	private boolean isModifyValidata(SaturnParameter parameter){
//		for(SaturnValidate oldValidate : this.validates){
//			for(SaturnValidate newSaturnValidate : parameter.getValidates()){
//				if(oldValidate.equals(newSaturnValidate)==false){
//					return false;
//				}
//			}
//		}
//		return true;
//	}
	
	private boolean isModifyValidata(SaturnParameter parameter){
		if(this.validates.size()!=parameter.getValidates().size()){
			this.validates = parameter.getValidates();
			return false;
		} else {
			for(SaturnValidate oldValidate : this.validates){
				for(SaturnValidate newSaturnValidate : parameter.getValidates()){
					if(oldValidate.equals(newSaturnValidate)==false){
						return false;
					}
				}
			}
		}
		
		return true;
	}
	
	
	private String id = "-1";

	private String name = "";

	private String classType = "java.lang.String";

	private String passingType = "in";

	private String valueKey = "";

	private String description = "";

	private String scope = "1";

	private String isValidate = "true";

	private List<SaturnValidate> validates = new ArrayList<SaturnValidate>();

	public List<SaturnValidate> getValidates() {
		return validates;
	}

	public void setValidates(List<SaturnValidate> validates) {
		this.validates = validates;
	}

	public SaturnParameter() {

	}

	public SaturnParameter(SaturnParameter parameter) {
		this.id = parameter.id;
		this.name = parameter.name;
		this.classType = parameter.classType;
		this.passingType = parameter.passingType;
		this.valueKey = parameter.valueKey;
		this.description = parameter.description;
		this.scope = parameter.scope;
		this.validates = parameter.validates;
		this.isValidate = parameter.isValidate;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public String getClassType() {
		return classType;
	}

	public String getPassingType() {
		return passingType;
	}

	public String getDescription() {
		return description;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setClassType(String classType) {
		this.classType = classType;
	}

	public void setPassingType(String passingType) {
		this.passingType = passingType;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getValueKey() {
		return valueKey;
	}

	public void setValueKey(String valueKey) {
		this.valueKey = valueKey;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}

	public int compareTo(SaturnParameter parameter) {
		if (this.id != null) {
			int idInt = Integer.parseInt(id);
			int parameterIdInt = Integer.parseInt(parameter.getId());
			if (idInt > parameterIdInt) {
				return 1;
			} else if (idInt == parameterIdInt) {
				return 0;
			}
		}

		return -1;
	}

	public String toString() {
		return "";// this.classType + "#" + this.name;
	}

	public String getIsValidate() {
		return isValidate;
	}

	public void setIsValidate(String isValidate) {
		this.isValidate = isValidate;
	}

	public List<?> getChild() {

		return this.validates;
	}

	public void setChild(List<?> list) {

	}
}